<?php

/**
 * 用户邀请
 * @author Ice <iceinto@mallog.com.cn>
 */
class InviteUserModel extends BaseModel
{

    /**
     * 获取用户邀请用户信息
     * @param Array $where 查询条件
     * @param String $field 显示字段
     * @return Array 用户信息
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getInviteUser($where = null, $limit = null, $field = 'm_users.id,m_users.`name`,m_users.`status`')
    {
        return $this->field($field)
            ->join('INNER JOIN m_users ON m_invite_user.invite_uid = m_users.id')
            ->where($where)
            ->limit($limit)
            ->select();
    }

    /**
     * 获取用户邀请好友数量
     * @param int $uid 用户标识
     * @return int 好友数量
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getInviteUserCount($uid)
    {
        $map = array();
        $map['uid'] = $uid;
        return $this->where($map)->count();
    }

    /**
     * 获取邀请用户通过手机验证的数量
     * @param int $uid 用户标识
     * @return int 好友数量
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getInviteUserPhoneCount($uid)
    {
        $map = array();
        $map['m_invite_user.uid'] = intval($uid);
        $map['m_users.status'] = 2; //手机认证
        return $this->join('INNER JOIN m_users ON m_invite_user.invite_uid = m_users.id')
            ->where($map)
            ->count();
    }

    public function getUsers($uid, $limit)
    {
        $map = array();
        $map['m_invite_user.uid'] = intval($uid);
        return $this->getInviteUser($map, $limit);
    }
}